import type { SourceTrackForm, SourceTrackQuery, SourceTrackVO } from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 分页查询登记来源追踪列表
 * @param params
 * @returns 登记来源追踪列表
 */
export function sourceTrackPage(params?: SourceTrackQuery) {
  return requestClient.get<PageResult<SourceTrackVO>>(
    '/register/source/track/page',
    { params },
  );
}

/**
 * 查询登记来源追踪列表
 * @param params
 * @returns 登记来源追踪列表
 */
export function sourceTrackList(params?: SourceTrackQuery) {
  return requestClient.get<SourceTrackVO[]>('/register/source/track/list', {
    params,
  });
}

/**
 * 导出登记来源追踪列表
 * @param params
 * @returns 登记来源追踪列表
 */
export function sourceTrackExport(params?: SourceTrackQuery) {
  return commonExport('/register/source/track/export', params ?? {});
}

/**
 * 查询登记来源追踪详情
 * @param id id
 * @returns 登记来源追踪详情
 */
export function sourceTrackInfo(id: ID) {
  return requestClient.get<SourceTrackVO>(`/register/source/track/${id}`);
}

/**
 * 新增登记来源追踪
 * @param data
 * @returns void
 */
export function sourceTrackAdd(data: SourceTrackForm) {
  return requestClient.postWithMsg<void>('/register/source/track', data);
}

/**
 * 更新登记来源追踪
 * @param data
 * @returns void
 */
export function sourceTrackUpdate(data: SourceTrackForm) {
  return requestClient.putWithMsg<void>('/register/source/track', data);
}

/**
 * 更新登记来源追踪状态
 * @param data
 * @returns void
 */
export function sourceTrackUpdateStatus(data: SourceTrackForm) {
  const requestData = {
    id: data.id,
    status: data.status,
  };
  return requestClient.putWithMsg<void>(
    `/register/source/track/changeStatus`,
    requestData,
  );
}

/**
 * 删除登记来源追踪
 * @param id id
 * @returns void
 */
export function sourceTrackRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/register/source/track/${id}`);
}
